import org.apache.zookeeper.ZooKeeper;
import java.io.IOException;

public class ZooKeeperExample {
    public static void main(String[] args) {
        String connectString = "localhost:2181";
        int sessionTimeout = 3000;

        ZooKeeper zk = null;
        try {
            // 创建 ZooKeeper 实例
            zk = new ZooKeeper(connectString, sessionTimeout, event -> {
                System.out.println("ZooKeeper Event: " + event);
            });

            // 执行一些 ZooKeeper 操作
            // ...

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (zk != null) {
                try {
                    // 关闭 ZooKeeper 连接
                    zk.close();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

